package com.sangeng.controller;

import com.sangeng.entity.ResponseResult;
import com.sangeng.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
 private   ArticleService articleService;
//测试代码
//    @RequestMapping("/article")
//    public void testArticle(){
//        List<Article> list = articleService.list();
//        list.forEach(
//                article -> System.out.println(article)
//        );
//
//    }

    @GetMapping("/hotArticleList")
    public ResponseResult hotArticleList(){

        ResponseResult result = articleService.getHotarticleList();

        return  result;

    }

    @GetMapping("/articleList")
   public ResponseResult getArticleList(Integer pageNum,Integer pageSize,Long categoryId){


     return articleService.getArticleList(pageNum,pageSize,categoryId);

    }

@GetMapping("/{id}")
    public ResponseResult getArticleDetail(@PathVariable(value = "id") Long id){

       ResponseResult articleDetail = articleService.getArticledetails(id);
          return articleDetail;
    }


    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable Long id){

        return articleService.updateViewCount(id);
    }

}
